/**
 * @(#) AddressProxy.as
 *
 * @date		2009. 02. 18.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	 주소변경 - Proxy
 * 				
 */
package com.skt.common_hr.myprofile.model
{
	import com.skt.common_hr.myprofile.MyProfileFacade;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	
	import com.wcl.utils.DateUtil;
	import com.wcl.utils.StringUtil;
	
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class AddressProxy extends CommonProxy
	{
		public static const NAME:String = "AddressProxy";
		

		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function AddressProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * 주소를 저장함
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param   pernr: 사번
		 * 			PSTLZ: 우편번호
		 * 			LOCAT: 상세주소
		 * 			SUBTY: 주소 구분 (1-본적, 2-현주소, 3-주민등록주소)
		 * @return void
		 */
		public function save(pernr:String, PSTLZ:String, LOCAT:String, SUBTY:String="2"):void
		{
			var param:Object = new Object();
			param["I_PERNR"] = pernr;
			param["I_PSTLZ"] = PSTLZ;
			param["I_LOCAT"] = LOCAT;
			param["I_DATUM"] = DateUtil.today();
			param["I_SUBTY"] = SUBTY;
			
			loadData("Z_HR_0010",param, result, fault); 
		}

		public function newSave(pernr:String, year:String, addr:Array, type:String):void{
			var param:Object = new Object();
			param["I_PERNR"] = pernr;
			param["I_DATUM"] = year;
			param["I_SUBTY"] = type;	//1:본적, 2:현주소, 3:주민등록주소
			
			
			var tables:Object = new Object();
			tables["I_ADD"] = addr;
			saveData("Z_HR_0010", param, tables, result, fault);  
		} 
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(retCode==0) {
				facade.sendNotification(MyProfileFacade.SAVE_ADDRESS_COMPLETE, this);
			}
			else {
				facade.sendNotification(MyProfileFacade.SAVE_ADDRESS_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			facade.sendNotification(MyProfileFacade.SAVE_ADDRESS_FAILED, this);
		}
	}
}